
# =============================
# unit tests for distributed computing functionality
# =============================
if ( MPI_CXX_FOUND )

	# building the mpi test runner as as its own library because of the long
	# build time, which is now reduced to the link time for a shared library
	add_library( distrTests_main SHARED
		distrTests_main
	)

	target_link_libraries( distrTests_main PUBLIC
		MPI::MPI_CXX
		mpiHelpers
	)

	add_executable( distrTests "" )

	target_sources( distrTests PRIVATE
		mpiHelpers_test
		#
		structMeshIdxTranslation_test
		structMeshPartitioning_test
		structMeshPartHelper_functions
		structMeshPart_UniMesh_test
		structMeshPart_RectMesh_test
		structMeshPart_StructMesh_test
		structMeshDistribution_test
		structMesh_testFunctions.cpp
		structMesh_testFunctions.hpp
		structMeshPartHelper
	)

	target_link_libraries( distrTests PRIVATE
		testHelperFunctions
		distrTests_main
		mpiHelpers
		structMeshPart
	)

	target_include_directories( distrTests PRIVATE
		${CMAKE_CURRENT_SOURCE_DIR}
		${CMAKE_CURRENT_SOURCE_DIR}/..
	)

	add_custom_command(
		TARGET distrTests
		POST_BUILD
		COMMAND mpirun -np 4 --use-hwthread-cpus distrTests
		WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
		COMMENT "-- Running distributed computing tests..."
	)
endif()